package com.sgcc.epri.dcloud.controller;

import com.sgcc.epri.dcloud.pojo.Result;
import com.sgcc.epri.dcloud.pojo.TreeNode;
import com.sgcc.epri.dcloud.service.TreeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/tree")
@Api(description = "树形结构")
public class TreeController {

    @Autowired
    private TreeService treeService;

    @GetMapping("/select")
    public Result list(){
        return treeService.select();
    }

    @PostMapping("/insert")
    @ApiOperation("必须选确定是文件类型后，才能继续填写其他属性。两个时间解释要明确。字段解释：fileType：0:文件夹、1:文件、autoFlag：是否自动计算 0:自动、1:不自动、calStartTime：计算区间 yyyy-mm-dd；无上级节点的，parentId传0、level传1；calstop_time 计算截止时间；")
    public Result save(@RequestBody TreeNode person){
        return treeService.insert(person);
    }

    @PostMapping("/update")
    @ApiOperation("只许修改名称、是否自动计算、计算区间（考核时间）")
    public Result edit(@RequestBody TreeNode person){
        return treeService.update(person);
    }

    @DeleteMapping("/delete")
    @ApiOperation("树形结构id")
    public Result delete(@RequestParam(required = true) @ApiParam(value = "id", required = true) String id){
        return treeService.delete(id);
    }

}
